#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: backtick.sh
# Description: 
#    執行方法有
#    `command`
#    "command"
#    $(command)
#    (command)
#    {command}
#    eval "$command"
# Edit History: 
#   2011-02-25    File created.
#========================================================================

#`` mean Command substitution (the backquote or backtickthe key above the Tab key on most keyboards)
#Backticks are horribly outdated and should not be used any more -- using $() instead will save you many headaches

file=`ls`
echo $file
echo `ls`
file=$(ls)
echo $file
echo $(ls)

# $() is better than ``, but no, not all shells support $()
echo $(basename $(which dmesg)) #it works
#echo `basename `which dmesg`` #it fails
echo `basename \`which dmesg\`` #it works, but hard to read

#print 1234, multiple ``, $()
echo $(echo 1$(echo 2$(echo 3$(echo 4))))
echo `echo 1\`echo 2\\\`echo 3\\\\\\\`echo 4\\\\\\\`\\\`\``

for i in bash dash sh; do
echo $i:
$i <<'!'
ra=` printf %s 's%\([?:.%\\]\)%\\\1%g'`
rb=$(printf %s 's%\([?:.%\\]\)%\\\1%g')
printf %s\\n "$ra" "$rb"
!
done

for i in bash dash sh; do echo $i: && $i <<'!'
echo $i:
ra=` printf %s 's%\([?:.%\\\]\)%\\\\\1%g'`
rb=$(printf %s 's%\([?:.%\\]\)%\\\1%g')
printf %s\\n "$ra" "$rb"
!
done


#找到所有的apk,並且作sha1sum
i=1;
for apk in */*.apk
do
	#加上""可以避免空白,()等字元的問題,並且用$(),而非``	
    sha1=$(sha1sum "$apk" | awk '{ print $1 }')
    echo $sha1
    echo "[$i]:copy ./$apk to ../Adrd_sha1/$sha1.apk"
	#記得要加上""
    cp ./"$apk" ../Adrd_sha1/$sha1.apk
    i=`expr $i + 1`
done

#g="./小花花120_bbs.nduoa.com/Beautiful LiveWallpaper 1.3.apk"
#f=$(sha1sum "$g")
#echo $f

